C# 2d array value check [duplicate]
Posted
by
TLFTN
on Game Development
See other posts from Game Development
or by TLFTN
Published on 2013-11-02T12:42:39Z
Indexed on
2013/11/02
16:03 UTC
Read the original article
Hit count: 187
This question already has an answer here:
- 3-in-a-row or more logic 4 answers
I've managed to create a 2d array, then made it fill up with random numbers, like this:
int[,] grid = new int[5, 5] ;
Random randomNumber = new Random();
var rowLength = grid.GetLength(0);
var colLength = grid.GetLength(1);
for (int row = 0; row < rowLength; row++)
{
for (int col = 0; col < colLength; col++){
grid[row, col] = randomNumber.Next(5);
Console.Write(String.Format("{0}\t", grid[row, col]));}
Console.WriteLine();
}
This results in an array with random values. Example:
3 0 0 3 3
1 3 3 3 2
0 0 2 0 4
3 3 2 0 3
4 0 3 3 0
Notice those three 3s which are connected to each other(in the second row), now how would I check if there's a match like this?
© Game Development or respective owner